home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
BARNET
/
FREENET
/
FERGUSON
/
CLIENT_P
/
!Client_Ex
/
c
/
Address
next >
Wrap
Text File
|
1995-06-05
|
5KB
|
165 lines
/*
File: Address.c
Date: 31-May-1995
Author: © Duncan Ferguson
File Purpose: provide window to get server address with
Version: 0.01
*/
/* handle finding where the server machine is; if its not on the local */
/* machine ask the user for the right address */
/* ============================================================= */
/* | Include files | */
/* ============================================================= */
#include "Address.h"
#include "Connect.h"
#include "Client_Ex.h"
#include "NetLib:netdb.h"
#include "DeskLib:Error.h"
#include "DeskLib:Event.h"
#include "DeskLib:Handler.h"
#include "DeskLib:Icon.h"
#include "DeskLib:Msgs.h"
#include "DeskLib:Window.h"
#include "DeskLib:WIMP.h"
#include <string.h>
#include <assert.h>
/* ============================================================= */
/* | #Definitions | */
/* ============================================================= */
#define LOCAL_HOST_NAME "localhost"
/* ============================================================= */
/* | Structures | */
/* ============================================================= */
enum {
address_TEXT = 2,
address_OK,
address_CANCEL
};
/* ============================================================= */
/* | Global variables | */
/* ============================================================= */
static window_handle Address_Window = 0;
static char HostAddress[MAXHOSTNAMELEN+1];
/* ============================================================= */
/* | Function Prototypes | */
/* ============================================================= */
static void Address_OpenWindow(void);
static void Address_CloseWindow(void);
static BOOL Address_ClickHandler(event_pollblock *event, void *reference);
static BOOL Address_Delete(event_pollblock *event, void *reference);
/* ============================================================= */
/* | External functions | */
/* ============================================================= */
extern void Address_ContactServer(void)
{
/* first check on local address before we do anything else */
if(!Connect_ContactServer(LOCAL_HOST_NAME))
{
/* local server not found, so get from user */
strcpy(HostAddress, LOCAL_HOST_NAME);
Address_OpenWindow();
}
/* otherwise it seems we found the server */
}
/* ============================================================= */
/* | Internal functions | */
/* ============================================================= */
/* open window to ask user for server address */
static void Address_OpenWindow(void)
{
if(!Address_Window)
{
Address_Window = Window_CreateAndShow("GetServAddr", 0, open_CENTERED);
/* error occured in getting template */
if(Address_Window == 0)
{
Msgs_Report(0, "no.template");
Client_Ex_RequestQuit();
return;
}
Icon_SetText(Address_Window, address_TEXT, HostAddress);
Icon_SetCaret(Address_Window, address_TEXT);
Event_Claim(event_CLOSE, Address_Window, event_ANY, Address_Delete,
&Address_Window);
Event_Claim(event_OPEN, Address_Window, event_ANY, Handler_OpenWindow,
NULL);
Event_Claim(event_CLICK, Address_Window, event_ANY, Address_ClickHandler,
NULL);
}
}
static BOOL Address_ClickHandler(event_pollblock *event, void *reference)
{
/* kill compiler warning */
UNUSED(reference);
switch(event->data.mouse.icon)
{
case address_OK:
Icon_GetText(Address_Window, address_TEXT, HostAddress);
Address_CloseWindow();
if(!Connect_ContactServer(HostAddress))
{
Address_OpenWindow();
}
else
{
/* server apparently found at this point */
}
break;
case address_CANCEL:
Address_CloseWindow();
Client_Ex_RequestQuit();
break;
}
return TRUE;
}
static void Address_CloseWindow(void)
{
if(Address_Window)
{
Window_Delete(Address_Window);
Address_Window = 0;
}
}
/* ============================================================= */
/* | Notes | */
/* ============================================================= */
static BOOL Address_Delete(event_pollblock *event, void *reference)
{
window_handle *window = reference;
assert(event->data.openblock.window == *window);
/* make sure handles match each other */
Window_Delete(event->data.openblock.window);
*window = 0;
/* is the window was closed with the cross, kill the program off */
Client_Ex_RequestQuit();
return TRUE;
}